package businessError

type Status struct {
	Code         int    `json:"code"`
	Status       string `json:"status"`
	Success      bool   `json:"success"`
	Message      string `json:"message"`
	ErrorMessage string `json:"errorMessage"`
}

// New 系统请求成功时返回
func New(code int, msg ...string) *Status {
	message := ""
	status := "done"
	success := false

	// 200为请求成功
	if code == 200 {
		success = true
	} else {
		status = "error"
	}
	if len(msg) <= 0 {
		message = GetMsg(code)
	} else {
		message = msg[0]
	}
	if success {
		return &Status{
			Code:    code,
			Status:  status,
			Success: true,
			Message: message,
		}
	} else {
		return &Status{
			Code:         code,
			Success:      true,
			Status:       status,
			Message:      message,
			ErrorMessage: message,
		}
	}
}

func (b *Status) Error() string {
	return b.Message
}
